package IOPeration;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Addbook implements Ioperation{
    public void work(BookList booList){
        System.out.println("添加图书");
        //要想添加图书首先要考虑：1.判断是否已放满；
        //                   2.构建对象；
        //                   3.判断书架有没有这本书；
        //                   4.插入这本书；
      int currenTsize= booList.getUsedsize();
      if(currenTsize== booList.getBooks().length){
          System.out.println("书架满了，不能放书了");
      }
        Scanner scanner=new Scanner(System.in);
      System.out.println("请输入书名");
      String name= scanner.nextLine();
      System.out.println("请输入作者名");
      String author= scanner.nextLine();
      System.out.println("请输入书的类型");
      String type=scanner.nextLine();
      System.out.println("请输入书的价格");
      int price= scanner.nextInt();
      Book newbook=new Book("name","author","type",price);
      for(int i=0;i<currenTsize;i++){
          Book book=booList.getBooks(i);
          if(book.getName().equals(name)){
              System.out.println("有这本书不能插入了");
              return;
          }

      }
        booList.setBooks(currenTsize,newbook);
        booList.setUsedsize(currenTsize+1);
        System.out.println("新增图书成功");



    }
}
